// SISTEMA : SISTEMA DE IDENTIFICACAO CRIMINAL
// PROGRAMA : SCRP1500
// OBJETIVO : MENU DE USUARIOS
// DATA : 25 DE JUNHO DE 1998
package br.com.vti.sisp_sicrim.antigo.controller.programa;

import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm1500;
import br.com.vti.sisp_sicrim.antigo.util.ExceptionProgram;
import br.com.vti.sisp_sicrim.antigo.util.Scrg001;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe : Scrp1500 OBJETIVO : MENU DE USUARIOS *
 * 
 * @author Incode - Data: mai/2014
 * 
 */

@Resource
@Path("/antigo/scrp1500")
public class Scrp1500 {
	Scrp1500 scrp1500Anterior;
	private String faseproc = "0";
	// Telas/relatorios utilizados
	Scrm1500 scrm1500;
	// Areas globais / session
	Scrg001 scrg001; // Funcoes/subrotinas
	FuncoesGerais funcoes = new FuncoesGerais();
	Result result;
	Sessao sessao;
	Boolean primeiraVez = false;

	private Scrm1500 preMapas() {
		sessao.getScrg001().setWVltw(7);
		sessao.getScrg001().setWFuncaow("* INSTITUTO DE IDENTIFICACAO *");
		sessao.getScrg001().setWProgramaw(this.getClass().getSimpleName().toUpperCase());

		scrm1500 = new Scrm1500(true, sessao);
		scrm1500.setjEmpresaj("GEJUSPC");
		return scrm1500;
	}

	public Scrp1500(Result result, Sessao sessao) {
		this.result = result;
		this.sessao = sessao;
	}

	@Post
	public void executar(Scrm1500 scrm1500) {
		try {
			main(scrm1500);
		} catch (Exception e) {
			ExceptionProgram excp = new ExceptionProgram();
			excp.trataErroScrcerro(e, sessao, this.getClass().getSimpleName());
		}
	}

	private void main(Scrm1500 pscrm1500) {
		if (pscrm1500 == null) {
			primeiraVez = true;
			// scrm1500 = new Scrm1500 (primeiraVez);
			scrm1500 = preMapas();
			scrm1500.setNavegar("../scrp1500/executar");
			sessao.setAtributo("Scrp1500", this);
			result.include("scrm1500", scrm1500);
			scrm1500.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		} else {
			restaurarEstados(pscrm1500);
		}

		scrm1500.receberTela(false, result);

		if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
			Scrpp001 scrpp001 = new Scrpp001(this.result, this.sessao);
			scrpp001.executar(null);
			return;
		}

		switch (scrm1500.getOpc().trim().toUpperCase()) {
		case "IUS": {
			if (sessao.getScrg001().getWNivelw() < 9) {
				scrm1500.enviarMensagem(null, "USUARIO NAO AUTORIZADO");
				sessao.setAtributo("Scrp1500", this);
				result.include("scrm1500", scrm1500);
				scrm1500.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			Scrp1510 scrp1510 = new Scrp1510(this.result, this.sessao);
			scrp1510.executar(null);
			return;
		}
		case "AUS": {
			if (sessao.getScrg001().getWNivelw() < 9) {
				scrm1500.enviarMensagem(null, "USUARIO NAO AUTORIZADO");
				sessao.setAtributo("Scrp1500", this);
				result.include("scrm1500", scrm1500);
				scrm1500.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			Scrp1520 scrp1520 = new Scrp1520(this.result, this.sessao);
			scrp1520.executar(null, null);
			return;
		}
		case "PUS": {
			if (sessao.getScrg001().getWNivelw() < 9) {
				scrm1500.enviarMensagem(null, "USUARIO NAO AUTORIZADO");
				sessao.setAtributo("Scrp1500", this);
				result.include("scrm1500", scrm1500);
				scrm1500.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			Scrp1530 scrp1530 = new Scrp1530(this.result, this.sessao);
			scrp1530.executar(null, null);
			return;
		}
		case "RUS": {
			if (sessao.getScrg001().getWNivelw() < 9) {
				scrm1500.enviarMensagem(null, "USUARIO NAO AUTORIZADO");
				sessao.setAtributo("Scrp1500", this);
				result.include("scrm1500", scrm1500);
				scrm1500.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			Scrp1540 scrp1540 = new Scrp1540(this.result, this.sessao);
			sessao.setAtributo("menu_retorno", this.getClass().getName());
			scrp1540.executar(null);
			return;
		}
		case "CAD": {
			Scrpp001 scrpp001 = new Scrpp001(this.result, this.sessao);
			scrpp001.executar(null);
			return;
		}
		default: {
			break;
		}
		}

		sessao.setAtributo("Scrp1500", this);
		result.include("scrm1500", scrm1500);
		scrm1500.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
	}

	private void restaurarEstados(Scrm1500 pscrm1500) {
		this.scrp1500Anterior = (Scrp1500) sessao.getAtributo("Scrp1500");
		if (pscrm1500 != null) {
			scrm1500 = pscrm1500;
			scrm1500.setjVersaoj(sessao.getScrg001().getWVersaow());
			scrm1500.setjEmpresaj("GEJUSPC");
			scrm1500.setjProgramaj(sessao.getScrg001().getWProgramaw());
		} else {
			scrm1500 = this.scrp1500Anterior.scrm1500;
		}
		scrm1500.setSessao(sessao);
		this.faseproc = this.scrp1500Anterior.faseproc;
	}

}
